package cn.scw.project.goods.controller;

import cn.scw.common.constant.SysConsts;
import cn.scw.framework.aspectj.lang.annotation.Log;
import cn.scw.framework.aspectj.lang.enums.BusinessType;
import cn.scw.framework.web.controller.BaseController;
import cn.scw.framework.web.domain.AjaxResult;
import cn.scw.framework.web.page.TableDataInfo;
import cn.scw.project.goods.domain.GAdvertising;
import cn.scw.project.goods.domain.netework.bean.GAdvertisingAddReq;
import cn.scw.project.goods.service.IGAdvertisingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 广告Controller
 *
 * @author api
 * @date 2020-05-20
 */
@Api(tags = "广告")
@RestController
@RequestMapping(SysConsts.CONTEXT_PATH+"/goods/advertising")
public class GAdvertisingController extends BaseController {
    @Autowired
    private IGAdvertisingService gAdvertisingService;


    @ApiOperation("查询广告列表")
    //@PreAuthorize("@ss.hasPermi('goods:advertising:list')")
    @GetMapping("/list")
    public TableDataInfo list(String facilityCode) {
        startPage();
        List<GAdvertising> list = gAdvertisingService.selectGAdvertisingList(facilityCode);
        return getDataTable(list);
    }

    @ApiOperation("查询广告列表")
    //@PreAuthorize("@ss.hasPermi('goods:advertising:list')")
    @GetMapping("/wx/list")
    public TableDataInfo wxList(String facilityCode) {
        startPage();
        List<GAdvertising> list = gAdvertisingService.selectGAdvertisingList(facilityCode);
        return getDataTable(list);
    }

    @ApiOperation("获取广告详细信息")
    //@PreAuthorize("@ss.hasPermi('goods:advertising:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(gAdvertisingService.selectGAdvertisingById(id));
    }

    @ApiOperation("获取广告详细信息")
    //@PreAuthorize("@ss.hasPermi('goods:advertising:query')")
    @GetMapping(value = "/wx/{id}")
    public AjaxResult getInfoByWx(@PathVariable("id") Long id) {
        return AjaxResult.success(gAdvertisingService.selectGAdvertisingById(id));
    }

    @ApiOperation("新增广告")
    //@PreAuthorize("@ss.hasPermi('goods:advertising:add')")
    @Log(title = "广告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(GAdvertisingAddReq req) {
        return toAjax(gAdvertisingService.insertGAdvertising(req));
    }

    @ApiOperation("修改广告")
    //@PreAuthorize("@ss.hasPermi('goods:advertising:edit')")
    @Log(title = "广告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(GAdvertisingAddReq req) {
        return toAjax(gAdvertisingService.updateGAdvertising(req));
    }

    @ApiOperation("删除广告")
    //@PreAuthorize("@ss.hasPermi('goods:advertising:remove')")
    @Log(title = "广告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(gAdvertisingService.deleteGAdvertisingByIds(ids));
    }
}
